<div id="main">
    <div id="contents_stat">
        <form method="post" action="#" name="filters">
            <fieldset>
                <legend>
                    <label sid="wrom_status.internet_config"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                        <tr id="trconnstat">
                            <td class="frame_tab_left">
                                <label sid="wrom_status.connstatus"></label>
                            </td>
                            <td id="connStatus" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wrom_status.connect_type"></label>
                            </td>
                            <td class="frame_tab_right">
                                <span id="connType"></span>
                                <span style="color: red;font-weight: bold;font-size: 15px;display: none" id="connType_3g">
                                    <label sid="wan.G3_escape"></label>
                                </span>
                            </td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wrom_status.wan_ipaddr"></label>
                            </td>
                            <td id="wanIP" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wrom_status.subnet_mask"></label>
                            </td>
                            <td id="wanMask" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wrom_status.default_gateway"></label>
                            </td>
                            <td id="gateway" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wrom_status.primary_dns"></label>
                            </td>
                            <td id="dns1" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wrom_status.secondary_dns"></label>
                            </td>
                            <td id="dns2" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wrom_status.mac"></label>
                            </td>
                            <td id="wanMac" class="frame_tab_right"></td>
                        </tr>
                   <!--     <tr width="80%">
                            <td colspan="2">

                                  <div style="width: 80%;margin: auto auto;font-weight: 700;font-size:15px;display: none;">

                                      <label sid="wan.G3_total" class="g3_css"></label>
                                      <span class="g3_css">800MB</span>
                                      <label sid="wan.G3_total_info" class="g3_css"></label>

                                  </div>
                                <div style="width: 80%;margin: auto auto;">

                                    <label sid="wan.G3_usedGprs" class="g3_css"></label>
                                    <span style="font-weight: 700;font-size:18px;color: #158144">70MB</span>
                                    <label sid="wan.G3_usedGprs_info" class="g3_css"></label>
                                </div>

                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                            <div class="graph"  style="height: 40px;">
                                <strong class="bar" style="width:20%;">
                                    <span>
                                       20%
                                    </span>
                                </strong>
                            </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                               <div style="width: 80%;margin: auto auto">
                                    <span> <label sid="wan.G3_rest"></label><label id="3g_rest"></label></span>
                                    <span style="color: #158144;font-weight: bold;">800M</span> |
                                    <label sid="wan.G3_used"></label>&nbsp;<label id="G3_used">0KB</label>
                                    <label sid="wan.G3_upload"></label>&nbsp; <label id="G3_upload">0KB</label>
                                    <label sid="wan.G3_download"></label>&nbsp;<label id="G3_download">0KB</label>
                               </div>
                            </td>
                        </tr>-->
                        <tr>
                            <td colspan="2"></td>
                        </tr>
                        <tr id="trconn">
                            <td class="frame_tab_center" colspan="2">
                                <input sid="sbutton.disconn" class = "button" type ="button" name = "disconn" id="disconn"/>
                                <input sid="sbutton.conn" class = "button" type ="button" name = "conn" id="conn"/>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
            <fieldset>
                <legend>
                    <label sid="menu.wireless_settings"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wireless.functions"></label>
                            </td>
                            <td id="w_functions" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wireless_basic.ssid"></label>
                            </td>
                            <td id="ssid" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wireless.model"></label>
                            </td>
                            <td id="model" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="station.channel"></label>
                            </td>
                            <td id="channel" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wireless_basic.ht_channel_bandwidth"></label>
                            </td>
                            <td id="channel_bandwidth" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wireless_basic.w_mac"></label>
                            </td>
                            <td id="bssid" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid="wireless.wds"></label>
                            </td>
                            <td id="wds" class="frame_tab_right"></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
            <fieldset>
                <legend>
                    <label sid=" wrom_status.local_network"></label>
                </legend>
                <div class="frame_tab_layer">
                    <table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
                        <tbody>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid=" wrom_status.lan_ipaddr"></label>
                            </td>
                            <td id="lanIP" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid=" wrom_status.local_netmask"></label>
                            </td>
                            <td id="lanMask" class="frame_tab_right"></td>
                        </tr>
                        <tr>
                            <td class="frame_tab_left">
                                <label sid=" wrom_status.mac"></label>
                            </td>
                            <td id="lanMac" class="frame_tab_right"></td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </fieldset>
        </form>
    </div>
</div>
<script type="text/javascript" src="js/libTable.js"></script>
<script type="text/javascript">
	load_html();


    function loadData(){
        var flag = $("#wrom_status_main_load").hasClass("current");
        if(flag){
            load_html()
        }else{
            clearInterval(tts);
        }
    }

   var tts = setInterval(function(){
       loadData();
    },10000);
function load_html(){
	DataRequest("/cgi-bin/stat?sysinfo","",function(data){
        var connType = data["connType"];
        var NetSwithchEn =data["NetSwithEn"];
        if(connType=="3G"&&NetSwithchEn=="on"){
            $("#connType").hide();
            $("#connType_3g").show();
        }else{
            $("#connType").show();
            $("#connType_3g").hide();
            $("#connType").html(connType=="PPPOE"?"PPPoE":connType);
        }

		$("#wanIP").html(data["wanIP"]);
		$("#wanMask").html(data["wanMask"]);
		$("#gateway").html(data["gateway"]);
		$("#wanMac").html(data["wanMac"]);
		$("#lanIP").html(data["lanIP"]);
		$("#lanMask").html(data["lanMask"]);
		$("#lanMac").html(data["lanMac"]);

		$.ajax({
		type:"POST",url:"status?get&param=WROC_wanStatus",dataType:"text",error:function (xml) {
			$(xml).find('Error').each(function () {
				var errortext = $(this).attr('msg');
				//show_message("err",errortext);
				alert(errortext);
			});
		},success:function (xml) {
			if($.trim(xml)=="1"){
				$("#connStatus").html(wrom_status.connstatus1);
				$("[name=conn]").attr("disabled",true);
				$("[name=disconn]").attr("disabled",false);
				$("#dns1").html(data["dns1"]);
				$("#dns2").html(data["dns2"]);
			}else if($.trim(xml)=="2"){
				$("#connStatus").html(wrom_status.connstatus2);
				$("[name=conn]").attr("disabled",false);
				$("[name=disconn]").attr("disabled",false);
			}else if($.trim(xml)=="3"){
				$("#connStatus").html(wrom_status.connstatus3);
				$("[name=conn]").attr("disabled",false);
				$("[name=disconn]").attr("disabled",true);
				$("#dns1").html("");
				$("#dns2").html("");
			}else if($.trim(xml)=="4"){
				$("#connStatus").html(wrom_status.connstatus4);
				$("[name=conn]").attr("disabled",true);
				$("[name=disconn]").attr("disabled",true);
			}else if($.trim(xml)=="5"){
				$("#connStatus").html(wrom_status.connstatus5);
				$("[name=conn]").attr("disabled",true);
				$("[name=disconn]").attr("disabled",false);
			}
			getwireless();
		}
	});
	if(data["connType"]=="DHCP"||data["connType"]=="STATIC"){
			$("#trconn").hide();
			}else{
				$("#trconn").show();
			}
	});
}

  $("[name=conn]").click(function () {
    	$.ajax({
		type:"POST",url:"status?get&param=WROC_pppConnect",dataType:"text",error:function (xml) {
			$(xml).find('Error').each(function () {
				var errortext = $(this).attr('msg');
				//show_message("err",errortext);
				alert(errortext);
			});
		},success:function (xml) {
			if($.trim(xml)=="success"){
			load_html();
			}
		}
	});
    });
    
    $("[name=disconn]").click(function () {
        $.ajax({
		type:"POST",url:"status?get&param=WROC_pppDisconnect",dataType:"text",error:function (xml) {
			$(xml).find('Error').each(function () {
				var errortext = $(this).attr('msg');
				//show_message("err",errortext);
				alert(errortext);
			});
		},success:function (xml) {
			if($.trim(xml)=="success"){
				load_html();
			}
		}
	});
    });
    
       function getbssid(){
 	DataRequest("/cgi-bin/stat?bssid","",function(data){
		var tmpvalue = data["bssid"];
		$("#bssid").html(tmpvalue);
	});
 	}
 	   function getwds(){
 		DataRequest("status?get&param=WROC_wdsInfo","",function(data){
			var wdsinfo = data["wdsinfo"];
			wdsinfo = wdsinfo.substr(0,wdsinfo.length-1);
			var wdsinfoarray= new Array();
			if(wdsinfo!==""&&wdsinfo.indexOf(";")>=0){
				wdsinfoarray=wdsinfo.split(";");
			}else if(wdsinfo!==""){
				wdsinfoarray[0]=wdsinfo;
			}
			
			var arraylength = wdsinfoarray.length;
			
			var infostr1 = "";
			var infostr2 = "";
			if(arraylength==1){
				infostr1=" (MAC:"+wdsinfoarray[0]+")";
				if(wdsinfoarray[0].split(",")[2]=="1"&&wdsinfoarray[0].split(",")[3]=="1"){
					infostr2=" MAC:"+wdsinfoarray[0].split(",")[0]+",";
				}
			}else if(arraylength > 1){
				for(var i=0; i<=arraylength; i++){
					infostr1 += " (MAC:"+wdsinfoarray[i]+")";
					if(wdsinfoarray[i].split(",")[2]=="1"&&wdsinfoarray[i].split(",")[3]=="1"){
						infostr2 += " MAC:"+wdsinfoarray[i].split(",")[0]+",";
					}
				}
			}
			 infostr2 = infostr2.substr(0,infostr2.length-1);
			 if(infostr2!==""){
			 var infostr2_length = infostr2.split(",").length;
			}else{
				var infostr2_length = 0;
			}
			 infostr2 ="("+infostr2;
			 infostr2 += ")";
			
	DataRequest("get_json","&id=2272",function(data){
			var value2272 = data["id2272"];
			if(value2272=="0"){
					$("#wds").html(wireless.wds_stat1);
				}else if(value2272=="4"){
					if(wdsinfo!==""){
						$("#wds").html(wireless.wds_stat3+infostr1);
					}else{
						$("#wds").html(wireless.wds_stat2);
						}
				}else if(value2272=="2"&&wdsinfo!==""){
					if(infostr2_length!==0){
						$("#wds").html(wireless.wds_stat3+infostr2);
					}else{
						$("#wds").html(wireless.wds_stat2);
						}
				}else if(value2272=="3"&&wdsinfo!==""){
					if(infostr2_length!==0){
						$("#wds").html(wireless.wds_stat3+infostr2);
					}else{
						$("#wds").html(wireless.wds_stat2);
						}
				}else{
					$("#wds").html(wireless.wds_stat1);
					}
		getbssid();
	});
		
	});
 		}
 		function getwireless(){
 			DataRequest("get_json","&id=2292&id=2164&id=2165&id=2167&id=2248",function(data){
			var functions = data["id2292"];
			var ssid = data["id2164"];
			var model = data["id2165"];
			var channel = data["id2167"];
			var channel_bandwidth = data["id2248"];
			if(functions=="on"){
				$("#w_functions").html(wireless.on);
				}else{
					$("#w_functions").html(wireless.off);
				}
			$("#ssid").html(ssid);

			if(model=="0"){
					$("#model").html("802.11b+g");
				}else if(model=="1"){
					$("#model").html("802.11b");
				}else if(model=="4"){
					$("#model").html("802.11g");
				}else if(model=="9"){
					$("#model").html("802.11b+g+n");
				}else if(model=="6"){
					$("#model").html("802.11n");
				}
				
				if(channel=="0"){
					$("#channel").html(wireless.auto);
				}else{
					$("#channel").html("channel "+channel);
				}
						
						if(channel_bandwidth=="0"){
							$("#channel_bandwidth").html("20 MHZ");
						}else{
							$("#channel_bandwidth").html("20/40 MHZ");
						}
					getwds();	
	});
 			}
</script>
